package com.bblocks.common.anti_reptile.data;

import java.time.LocalDate;

/**
 * 全局变量
 * @author Jin
 * @since 2024/3/23 10:14
 */
public class AntiEsStatConsts {

    /**
     * 写入ip用户数量sql
     */
    public static final String SAVE_IP_NUM_SQL = "INSERT INTO sys_access_ip_sum (ip, user_num,day) VALUES (?, ?,?)";
    /**
     * 写入url的ip访问qps的sql
     */
    public static final String SAVE_IP_ACCESS_SQL = "insert into sys_access_sum(url,day,rate_avg_ip,rate_max_ip) values(?,?,?,?) ON DUPLICATE KEY UPDATE rate_avg_ip=VALUES(rate_avg_ip),rate_max_ip=VALUES(rate_max_ip)" ;
    /**
     * 写入url的用户访问qps的sql
     */
    public static final String SAVE_USER_ACCESS_SQL = "insert into sys_access_sum(url,day,rate_avg_user,rate_max_user) values(?,?,?,?) ON DUPLICATE KEY UPDATE rate_avg_user=VALUES(rate_avg_user),rate_max_user=VALUES(rate_max_user)" ;

    /**
     * 写入url的平台户访问qps的sql
     */
    public static final String SAVE_PLATE_ACCESS_SQL = "insert into sys_access_sum(url,day,rate_avg_plate,rate_max_plate) values(?,?,?,?) ON DUPLICATE KEY UPDATE rate_avg_plate=VALUES(rate_avg_plate),rate_max_plate=VALUES(rate_max_plate)" ;

    /**
     *  数据记录第一条
     */
    public static final String ACCESS_SUM_FISRT_SQL = "select * from sys_access_sum where day is not null order by id asc limit 1";

    /**
     * 一条ip访问记录
     */
    public static  final String IP_SUM_SQL = "select * from sys_access_ip_sum where day is null and ip=?";


    /**
     * 删除最终的访问记录
     */
    public static final String DELETE_ACCESS_SUM_SQL = "DELETE FROM sys_access_sum WHERE  `DAY` IS NULL";

    /**
     * 重新生成访问记录
     */
    public static final String REINSERT_ACCESS_SUM_SQL = "INSERT INTO sys_access_sum (url, rate_avg_user,rate_max_user,rate_avg_ip,rate_max_ip,rate_avg_plate,rate_max_plate) SELECT url,avg(rate_avg_user),avg(rate_max_user),avg(rate_avg_ip),avg(rate_max_ip),,avg(rate_avg_plate),avg(rate_max_plate) FROM sys_access_sum WHERE `DAY` >=? GROUP BY url";


    /**
     *删除最终的Ip用户记录
     */
    public static final String DELETE_IP_SUM_SQL = "DELETE FROM sys_access_ip_sum WHERE  `DAY` IS NULL";
    /**
     * 重新生成最终Ip用户记录
     */
    public static final String REINSERT_IP_SUM_SQL = "INSERT INTO sys_access_ip_sum (ip, user_num) SELECT ip,avg(user_num) nums FROM sys_access_ip_sum WHERE `DAY` >=? GROUP BY ip";



    public static class EsJson{

        public static final String ip_day_users = "ip_day_users.json";
        public static final String ip_nologin_access = "ip_nologin_access.json";
        public static final String ip_nologin_access_qps = "ip_nologin_access_qps.json";
        public static final String user_access = "user_access.json";
        public static final String user_access_qps = "user_access_qps.json";
    }

}
